package monpkg.view;

import java.rmi.Naming;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import monpkg.entities.Student;
import monpkg.rmi.IStudentImpl;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 * @author Yannick Bouchot
 * @author Jonathan Romero
 */

public class index extends AbstractController {
	String urlStudentFactory = "rmi://localhost/studentFactory";
	
	private IStudentImpl studentFactory;

	//private Student message = new Student("NOM1", "PRENOM1", "mail@serv.com", "1234");
	/**
	 * methode permettant de relier la methode avec la factory du serveur
	 */
	@PostConstruct
	public void init() throws Exception
	{
		studentFactory = (IStudentImpl) Naming.lookup(urlStudentFactory);
		//annuaire = (IAnnuaire) Naming.lookup(url1);
		//annuaire.init();
		//auth = (IAuthentication) Naming.lookup(url2);
	}
	/**
	 * methode permettant de procder a la requete
	 */
	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		request.setAttribute("student", new Student("NOM1", "PRENOM2", "mail@serv.com", "1234"));
	}
	/**
	 * methode permettant de definir la vue de la servlet
	 */
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		//Student s = Student.("NOM1", "PRENOM2", "mail@serv.com", "1234");
		return new ModelAndView("indexPage", "test", "value");
	}
}
